// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Checkered Ball Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 74 : TYPE_CHECKEREDBALL

// Function declarations
reserve function CheckeredBall_DebugDraw
reserve function CheckeredBall_DebugSpawn
reserve function CheckeredBall_Function142
reserve function CheckeredBall_Function143
reserve function CheckeredBall_Function144
reserve function CheckeredBall_Function145
reserve function CheckeredBall_Function146
reserve function CheckeredBall_Function147
reserve function CheckeredBall_Function148

// Static Values

// Tables
private table CheckeredBall_table26
	0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 6, 7, 8, 9, 10, 12, 14, 16, 20
end table

private table CheckeredBall_table27
	253, 251, 248, 245, 243, 240, 237, 235, 232, 229, 226, 224, 221, 219, 216, 213, 210, 208, 205, 203, 200, 197, 195, 192
end table

function CheckeredBall_DebugDraw
	DrawSprite(1)
end function


function CheckeredBall_DebugSpawn
	CreateTempObject(TypeName[Checkered Ball], 0, object.xpos, object.ypos)
	object[tempObjectPos].gravity = GRAVITY_AIR
	object[tempObjectPos].value7 = object.xpos
	object[tempObjectPos].value8 = object.ypos
	object[tempObjectPos].value1 = object.xpos
	object[tempObjectPos].value2 = object.ypos
end function


function CheckeredBall_Function142
	object.value10 = 0
	temp2 = 0
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		CheckEqual(options.attractMode, 1)
		temp1 = checkResult
		CheckEqual(currentPlayer, 1)
		temp1 &= checkResult
		temp0 = object[currentPlayer].value21
		temp0 >>= 1
		if object[currentPlayer].gravity == GRAVITY_GROUND
			if object[currentPlayer].xvel < 0
				BoxCollisionTest(C_TOUCH, object.entityPos, 0, -22, 23, 22, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
				if checkResult == 1
					if object[currentPlayer].left == 1
						if temp1 == 0
							SetBit(object.value10, temp2, 1)
							temp1 = object[currentPlayer].value20
							FlipSign(temp1)
							if object.speed > temp1
								object.speed -= temp0
							end if
							object.value6 = 1
						end if
						object[currentPlayer].xpos = object[currentPlayer].collisionRight
						object[currentPlayer].xpos += 22
						object[currentPlayer].xpos <<= 16
						object[currentPlayer].xpos += object.value1
						if object.xvel < 0
							if object[currentPlayer].speed < object.speed
								object[currentPlayer].xvel = object.xvel
								object[currentPlayer].speed = object.speed
							end if
						end if
						object[currentPlayer].pushing = 2
					end if
				end if
			else
				if object[currentPlayer].xvel > 0
					BoxCollisionTest(C_TOUCH, object.entityPos, -23, -22, 0, 22, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
					if checkResult == 1
						if object[currentPlayer].right == 1
							if temp1 == 0
								SetBit(object.value10, temp2, 1)
								if object.speed < object[currentPlayer].value20
									object.speed += temp0
								end if
								object.value6 = 1
							end if
							object[currentPlayer].xpos = object[currentPlayer].collisionLeft
							object[currentPlayer].xpos += -22
							object[currentPlayer].xpos <<= 16
							object[currentPlayer].xpos += object.value1
							if object.xvel > 0
								if object[currentPlayer].speed > object.speed
									object[currentPlayer].xvel = object.xvel
									object[currentPlayer].speed = object.speed
								end if
							end if
							object[currentPlayer].pushing = 2
						end if
					end if
				end if
			end if
		end if
		temp2++
	next
end function


function CheckeredBall_Function143
	temp6 = object.xpos
	temp6 &= -0x10000
	temp6 -= object.value1
	temp7 = object.ypos
	temp7 &= -0x10000
	temp7 -= object.value2
	temp4 = object.xpos
	temp5 = object.ypos
	object.xpos = object.value1
	object.ypos = object.value2
	temp2 = 0
	foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
		GetBit(temp0, object.value10, temp2)
		if temp0 == 1
			if object[currentPlayer].xpos < object.xpos
				temp1 = object[currentPlayer].collisionRight
				FlipSign(temp1)
				temp1 -= 22
			else
				temp1 = object[currentPlayer].collisionLeft
				FlipSign(temp1)
				temp1 += 22
			end if
			temp1 <<= 16
			object[currentPlayer].xpos = temp1
			object[currentPlayer].xpos += temp4
		else
			BoxCollisionTest(C_BOX, object.entityPos, -22, -22, 22, 22, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				object[currentPlayer].xpos += temp6
				temp0 = temp6
				temp0 >>= 1
				object[currentPlayer].xpos += temp0
				object[currentPlayer].ypos += temp7
				if object[currentPlayer].xvel != 0
					temp0 = object[currentPlayer].value21
					temp0 >>= 2
					if object[currentPlayer].xvel > 0
						FlipSign(temp0)
					end if
				else
					temp0 = 0
				end if
				object.speed += temp0
				if temp0 != 0
					object.value6 = 1
				end if
				object.xpos = temp4
				object.ypos = temp5
				BoxCollisionTest(C_BOX, object.entityPos, -22, -22, 22, 22, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
				object.xpos = object.value1
				object.ypos = object.value2
				if checkResult == 0
					temp0 = temp6
					temp1 = temp6
					temp0 >>= 1
					temp1 += temp0
					object[currentPlayer].speed += temp0
					object[currentPlayer].xvel = object[currentPlayer].speed
					object[currentPlayer].gravity = GRAVITY_AIR
					object[currentPlayer].controlLock = 15
				end if
			end if
			if checkResult == 4
				if object.yvel >= 0
					if object[currentPlayer].gravity == GRAVITY_GROUND
						CallFunction(PlayerObject_Kill)
					end if
				end if
			end if
		end if
		temp2++
	next
	object.xpos = temp4
	object.ypos = temp5
end function


function CheckeredBall_Function144
	temp0 = object.xvel
	temp0 |= object.yvel
	if temp0 != 0
		ResetObjectEntity(object[arrayPos0].entityPos, TypeName[Blank Object], 0, object[arrayPos0].xpos, object[arrayPos0].ypos)
		Rand(checkResult, 32)
		if checkResult > 15
			CreateTempObject(animalType1, TypeName[Blank Object], object[arrayPos0].xpos, object[arrayPos0].ypos)
		else
			CreateTempObject(animalType2, TypeName[Blank Object], object[arrayPos0].xpos, object[arrayPos0].ypos)
		end if
		object[tempObjectPos].priority = PRIORITY_UNKNOWN
		CreateTempObject(TypeName[Smoke Puff], 0, object[arrayPos0].xpos, object[arrayPos0].ypos)
		object[tempObjectPos].drawOrder = 4
		CreateTempObject(TypeName[Object Score], object.value11, object[arrayPos0].xpos, object[arrayPos0].ypos)
		object[tempObjectPos].drawOrder = 4
		PlaySfx(SfxName[Destroy], 0)
		switch object.value11
		case 0
			player.score += 100
			break
		case 1
			player.score += 200
			break
		case 2
			player.score += 500
			break
		case 3
		case 4
		case 5
		case 6
		case 7
		case 8
		case 9
		case 10
		case 11
		case 12
		case 13
		case 14
			player.score += 1000
			break
		case 15
			player.score += 0x2710
			break
		end switch
		if object.value11 < 15
			object.value11++
		end if
	end if
end function


function CheckeredBall_Function145
	temp0 = object.xpos
	temp0 -= object[arrayPos0].xpos
	temp1 = object.ypos
	temp1 -= object[arrayPos0].ypos
	ATan2(temp2, temp0, temp1)
	Sin256(temp0, temp2)
	Cos256(temp1, temp2)
	object[arrayPos0].xvel = temp1
	object[arrayPos0].xvel *= -0x800
	object[arrayPos0].yvel = temp0
	object[arrayPos0].yvel *= -0x800
end function


function CheckeredBall_Function146
	switch object[arrayPos0].propertyValue
	case 0
		temp0 = object[arrayPos0].value1
		if object.gravity == GRAVITY_AIR
			temp0 = 1
		end if
		if object.collisionMode > CMODE_FLOOR
			if object.yvel < 0
				temp0 = 1
			end if
		end if
		if temp0 == 0
			BoxCollisionTest(C_BOX, object[arrayPos0].entityPos, -14, -8, 14, 8, object.entityPos, -22, -22, 22, 22)
			BoxCollisionTest(C_TOUCH, object[arrayPos0].entityPos, -14, -10, 14, -6, object.entityPos, -22, -22, 22, 22)
			if checkResult == 1
				object[arrayPos0].value0 = 1
				object.tileCollisions = 1
				object.gravity = GRAVITY_AIR
				object.speed = object.xvel
				object.yvel = temp7
				FlipSign(object.yvel)
				object.yvel += object[arrayPos0].value2
				PlaySfx(SfxName[Spring], 0)
			end if
		else
			if object.yvel >= 0
				BoxCollisionTest(C_PLATFORM, object[arrayPos0].entityPos, -14, -8, 14, 8, object.entityPos, -22, -22, 22, 22)
				BoxCollisionTest(C_TOUCH, object[arrayPos0].entityPos, -14, -10, 14, -6, object.entityPos, -22, -22, 22, 22)
				if checkResult == 1
					object[arrayPos0].value0 = 1
					object.tileCollisions = 1
					object.gravity = GRAVITY_AIR
					object.speed = object.xvel
					object.yvel = temp7
					FlipSign(object.yvel)
					object.yvel += object[arrayPos0].value2
					PlaySfx(SfxName[Spring], 0)
				end if
			end if
		end if
		break
	case 1
		BoxCollisionTest(C_BOX, object[arrayPos0].entityPos, -8, -14, 8, 14, object.entityPos, -22, -22, 22, 22)
		if object.gravity == GRAVITY_GROUND
			BoxCollisionTest(C_TOUCH, object[arrayPos0].entityPos, 6, -14, 10, 14, object.entityPos, -22, -22, 22, 22)
			if checkResult == 1
				object[arrayPos0].value0 = 1
				object.tileCollisions = 1
				object.speed = temp7
				object.collisionMode = CMODE_FLOOR
				object.direction = FLIP_NONE
				PlaySfx(SfxName[Spring], 0)
			end if
		end if
		break
	case 2
		BoxCollisionTest(C_BOX, object[arrayPos0].entityPos, -8, -14, 8, 14, object.entityPos, -22, -22, 22, 22)
		if object.gravity == GRAVITY_GROUND
			BoxCollisionTest(C_TOUCH, object[arrayPos0].entityPos, -10, -14, -6, 14, object.entityPos, -22, -22, 22, 22)
			if checkResult == 1
				object[arrayPos0].value0 = 1
				object.tileCollisions = 1
				object.speed = temp7
				FlipSign(object.speed)
				object.collisionMode = CMODE_FLOOR
				object.direction = FLIP_X
				PlaySfx(SfxName[Spring], 0)
			end if
		end if
		break
	case 3
		BoxCollisionTest(C_BOX, object[arrayPos0].entityPos, -14, -8, 14, 8, object.entityPos, -22, -22, 22, 22)
		BoxCollisionTest(C_TOUCH, object[arrayPos0].entityPos, -14, 6, 14, 10, object.entityPos, -22, -22, 22, 22)
		if checkResult == 1
			object[arrayPos0].value0 = 1
			if object.collisionMode == CMODE_ROOF
				FlipSign(object.speed)
				FlipSign(object.xvel)
			end if
			object.tileCollisions = 1
			object.gravity = GRAVITY_AIR
			object.speed = object.xvel
			object.yvel = temp7
			PlaySfx(SfxName[Spring], 0)
		end if
		break
	end switch
end function


function CheckeredBall_Function147
	if object[arrayPos0].state < 3
		if object.yvel >= 0
			temp0 = object.xpos
			temp0 -= object[arrayPos0].xpos
			temp0 >>= 17
			temp0 += 24
			if temp0 < 0
				temp0 = 0
			end if
			if temp0 > 47
				temp0 = 47
			end if
			if temp7 == 0
				GetTableValue(temp1, temp0, CLedgeLeft_table25)
			else
				temp2 = 47
				temp2 -= temp0
				GetTableValue(temp1, temp2, CLedgeLeft_table25)
			end if
			temp1 -= 84
			temp0 = temp1
			temp0 += 32
			BoxCollisionTest(C_PLATFORM, arrayPos0, -48, temp1, 48, temp0, object.entityPos, -18, -22, 18, 22)
			if checkResult == 1
				object.ypos += 0x40000
				if object[arrayPos0].state == 0
					object[arrayPos0].state = 1
				end if
			end if
		end if
	end if
end function


function CheckeredBall_Function148
	if object.gravity == GRAVITY_AIR
		object.yvel += 0x3800
		object.speed = object.xvel
	else
		Sin256(temp0, object.value4)
		temp0 *= 0x2000
		temp0 >>= 8
		object.speed += temp0
		object.value5 = object.speed
		if temp0 == 0
			if object.value6 == 0
				if object.speed > 0
					object.speed -= 0x400
					if object.speed < 0
						object.speed = 0
					end if
				else
					object.speed += 0x400
					if object.speed > 0
						object.speed = 0
					end if
				end if
			end if
		end if
		Cos256(temp0, object.value4)
		temp0 *= object.speed
		temp0 >>= 8
		object.xvel = temp0
		Sin256(temp0, object.value4)
		temp0 *= object.speed
		temp0 >>= 8
		object.yvel = temp0
	end if
	object.value6 = 0
end function


event ObjectMain
	if object.priority != PRIORITY_XBOUNDS_DESTROY
		object.priority = PRIORITY_ACTIVE
	end if
	CallFunction(CheckeredBall_Function142)
	object.value3 += object.value5
	object.collisionLeft = -22
	object.collisionTop = -22
	object.collisionRight = 22
	object.collisionBottom = 22
	CallFunction(CheckeredBall_Function148)
	ProcessObjectMovement()
	object.value4 = object.angle
	foreach (TypeName[Blank Object], arrayPos0, ACTIVE_ENTITIES)
		switch object[arrayPos0].type
		case 58
			BoxCollisionTest(C_TOUCH, object.entityPos, -22, -22, 22, 22, arrayPos0, -14, -14, 14, 14)
			if checkResult == 1
				CallFunction(CheckeredBall_Function144)
			end if
			break
		case 56
			BoxCollisionTest(C_TOUCH, object.entityPos, -22, -22, 22, 22, arrayPos0, -16, -7, 16, 7)
			if checkResult == 1
				CallFunction(CheckeredBall_Function144)
			end if
			break
		case 61
			BoxCollisionTest(C_TOUCH, object.entityPos, -22, -22, 22, 22, arrayPos0, -14, -14, 14, 14)
			if checkResult == 1
				CallFunction(CheckeredBall_Function144)
			end if
			break
		case 60
			BoxCollisionTest(C_TOUCH, object.entityPos, -22, -22, 22, 22, arrayPos0, -12, -14, 12, 14)
			if checkResult == 1
				CallFunction(CheckeredBall_Function144)
			end if
			break
		case 73
			BoxCollisionTest(C_TOUCH, object.entityPos, -22, -22, 22, 22, arrayPos0, -10, -20, 6, 20)
			if checkResult == 1
				CallFunction(CheckeredBall_Function144)
			end if
			break
		case 65
			switch object[arrayPos0].state
			case 2
			case 3
				BoxCollisionTest(C_TOUCH, object.entityPos, -22, -22, 22, 22, arrayPos0, -16, -8, 16, 8)
				if checkResult == 1
					CallFunction(CheckeredBall_Function144)
				end if
				break
			end switch
			break
		case 63
			switch object[arrayPos0].state
			case 2
			case 3
				BoxCollisionTest(C_TOUCH, object.entityPos, -22, -22, 22, 22, arrayPos0, -12, -14, 12, 14)
				if checkResult == 1
					CallFunction(CheckeredBall_Function144)
				end if
				break
			end switch
			break
		case 57
			BoxCollisionTest(C_TOUCH, object.entityPos, -22, -22, 22, 22, arrayPos0, -6, -6, 6, 6)
			if checkResult == 1
				CallFunction(CheckeredBall_Function145)
			end if
			break
		case 62
			BoxCollisionTest(C_TOUCH, object.entityPos, -22, -22, 22, 22, arrayPos0, -6, -6, 6, 6)
			if checkResult == 1
				CallFunction(CheckeredBall_Function145)
			end if
			break
		case 64
			BoxCollisionTest(C_TOUCH, object.entityPos, -22, -22, 22, 22, arrayPos0, -6, -6, 6, 6)
			if checkResult == 1
				CallFunction(CheckeredBall_Function145)
			end if
			break
		case 13
			BoxCollisionTest(C_TOUCH, object.entityPos, -22, -22, 22, 22, arrayPos0, -16, -14, 16, 16)
			if checkResult == 1
				object[arrayPos0].state = 0
				CreateTempObject(TypeName[Smoke Puff], 0, object[arrayPos0].xpos, object[arrayPos0].ypos)
				object[tempObjectPos].drawOrder = 4
				object[arrayPos0].type = TypeName[Broken Monitor]
				if object[arrayPos0].priority != PRIORITY_XBOUNDS_DESTROY
					object[arrayPos0].priority = PRIORITY_ACTIVE
				end if
				object[arrayPos0].alpha = 255
				object[arrayPos0].value0 = object[arrayPos0].ypos
				object[arrayPos0].value1 = -0x30000
				PlaySfx(SfxName[Destroy], 0)
			end if
			break
		case 43
			BoxCollisionTest(C_BOX, arrayPos0, -16, -16, 16, 16, object.entityPos, -22, -22, 22, 22)
			switch checkResult
			case 1
				object.gravity = GRAVITY_GROUND
				break
			case 2
				if object.speed > 0
					object.speed = 0
				end if
				break
			case 3
				if object.speed < 0
					object.speed = 0
				end if
				break
			end switch
			break
		case 35
			switch object[arrayPos0].propertyValue
			case 0
				BoxCollisionTest(C_BOX, arrayPos0, -20, -16, 20, 16, object.entityPos, -22, -22, 22, 22)
				break
			case 1
				BoxCollisionTest(C_BOX, arrayPos0, -16, -20, 15, 20, object.entityPos, -22, -22, 22, 22)
				break
			case 2
				BoxCollisionTest(C_BOX, arrayPos0, -15, -20, 16, 20, object.entityPos, -22, -22, 22, 22)
				break
			case 3
				BoxCollisionTest(C_BOX, arrayPos0, -20, -16, 20, 15, object.entityPos, -22, -22, 22, 22)
				break
			case 4
				BoxCollisionTest(C_BOX, arrayPos0, -4, -16, 4, 16, object.entityPos, -22, -22, 22, 22)
				break
			case 5
				BoxCollisionTest(C_BOX, arrayPos0, -16, -4, 15, 4, object.entityPos, -22, -22, 22, 22)
				break
			case 6
				BoxCollisionTest(C_BOX, arrayPos0, -15, -4, 16, 4, object.entityPos, -22, -22, 22, 22)
				break
			case 7
				BoxCollisionTest(C_BOX, arrayPos0, -4, -16, 4, 15, object.entityPos, -22, -22, 22, 22)
				break
			case 8
				BoxCollisionTest(C_BOX, arrayPos0, -28, -16, 28, 16, object.entityPos, -22, -22, 22, 22)
				break
			case 9
				BoxCollisionTest(C_BOX, arrayPos0, -16, -28, 15, 28, object.entityPos, -22, -22, 22, 22)
				break
			case 10
				BoxCollisionTest(C_BOX, arrayPos0, -15, -28, 16, 28, object.entityPos, -22, -22, 22, 22)
				break
			case 11
				BoxCollisionTest(C_BOX, arrayPos0, -28, -16, 28, 15, object.entityPos, -22, -22, 22, 22)
				break
			case 12
				BoxCollisionTest(C_BOX, arrayPos0, -64, -16, 64, 16, object.entityPos, -22, -22, 22, 22)
				break
			case 13
				BoxCollisionTest(C_BOX, arrayPos0, -16, -64, 15, 64, object.entityPos, -22, -22, 22, 22)
				break
			case 14
				BoxCollisionTest(C_BOX, arrayPos0, -15, -64, 16, 64, object.entityPos, -22, -22, 22, 22)
				break
			case 15
				BoxCollisionTest(C_BOX, arrayPos0, -64, -16, 64, 15, object.entityPos, -22, -22, 22, 22)
				break
			end switch
			switch checkResult
			case 1
				object.gravity = GRAVITY_GROUND
				break
			case 2
				if object.speed > 0
					object.speed = 0
				end if
				break
			case 3
				if object.speed < 0
					object.speed = 0
				end if
				break
			end switch
			break
		case 51
			if object[arrayPos0].propertyValue < 3
				temp0 = object.speed
				Abs(temp0)
				if temp0 >= 0x20000
					BoxCollisionTest(C_TOUCH, arrayPos0, -17, -32, 17, 32, object.entityPos, -22, -22, 22, 22)
					if checkResult == 1
						object[arrayPos0].type = TypeName[Blank Object]
						PlaySfx(SfxName[Jump], 0)
						temp0 = object[arrayPos0].propertyValue
						temp0 <<= 1
						temp0 += 3
						temp1 = temp0
						temp1++
						temp2 = object[arrayPos0].xpos
						temp2 -= 0x80000
						temp3 = object[arrayPos0].xpos
						temp3 += 0x80000
						temp4 = object[arrayPos0].ypos
						temp4 -= 0x180000
						if object.xpos < object[arrayPos0].xpos
							CreateTempObject(TypeName[Breakable Wall], temp0, temp2, temp4)
							object[tempObjectPos].xvel = -0x60000
							object[tempObjectPos].yvel = -0x60000
							object[tempObjectPos].drawOrder = 4
							CreateTempObject(TypeName[Breakable Wall], temp1, temp3, temp4)
							object[tempObjectPos].xvel = -0x40000
							object[tempObjectPos].yvel = -0x50000
							object[tempObjectPos].drawOrder = 4
							temp4 += 0x100000
							CreateTempObject(TypeName[Breakable Wall], temp0, temp2, temp4)
							object[tempObjectPos].xvel = -0x80000
							object[tempObjectPos].yvel = -0x20000
							object[tempObjectPos].drawOrder = 4
							CreateTempObject(TypeName[Breakable Wall], temp1, temp3, temp4)
							object[tempObjectPos].xvel = -0x60000
							object[tempObjectPos].yvel = -0x10000
							object[tempObjectPos].drawOrder = 4
							temp4 += 0x100000
							CreateTempObject(TypeName[Breakable Wall], temp0, temp2, temp4)
							object[tempObjectPos].xvel = -0x80000
							object[tempObjectPos].yvel = 0x20000
							object[tempObjectPos].drawOrder = 4
							CreateTempObject(TypeName[Breakable Wall], temp1, temp3, temp4)
							object[tempObjectPos].xvel = -0x60000
							object[tempObjectPos].yvel = 0x10000
							object[tempObjectPos].drawOrder = 4
							temp4 += 0x100000
							CreateTempObject(TypeName[Breakable Wall], temp0, temp2, temp4)
							object[tempObjectPos].xvel = -0x60000
							object[tempObjectPos].yvel = 0x60000
							object[tempObjectPos].drawOrder = 4
							CreateTempObject(TypeName[Breakable Wall], temp1, temp3, temp4)
							object[tempObjectPos].xvel = -0x40000
							object[tempObjectPos].yvel = 0x50000
							object[tempObjectPos].drawOrder = 4
						else
							CreateTempObject(TypeName[Breakable Wall], temp0, temp2, temp4)
							object[tempObjectPos].xvel = 0x40000
							object[tempObjectPos].yvel = -0x50000
							object[tempObjectPos].drawOrder = 4
							CreateTempObject(TypeName[Breakable Wall], temp1, temp3, temp4)
							object[tempObjectPos].xvel = 0x60000
							object[tempObjectPos].yvel = -0x60000
							object[tempObjectPos].drawOrder = 4
							temp4 += 0x100000
							CreateTempObject(TypeName[Breakable Wall], temp0, temp2, temp4)
							object[tempObjectPos].xvel = 0x60000
							object[tempObjectPos].yvel = -0x10000
							object[tempObjectPos].drawOrder = 4
							CreateTempObject(TypeName[Breakable Wall], temp1, temp3, temp4)
							object[tempObjectPos].xvel = 0x80000
							object[tempObjectPos].yvel = -0x20000
							object[tempObjectPos].drawOrder = 4
							temp4 += 0x100000
							CreateTempObject(TypeName[Breakable Wall], temp0, temp2, temp4)
							object[tempObjectPos].xvel = 0x60000
							object[tempObjectPos].yvel = 0x10000
							object[tempObjectPos].drawOrder = 4
							CreateTempObject(TypeName[Breakable Wall], temp1, temp3, temp4)
							object[tempObjectPos].xvel = 0x80000
							object[tempObjectPos].yvel = 0x20000
							object[tempObjectPos].drawOrder = 4
							temp4 += 0x100000
							CreateTempObject(TypeName[Breakable Wall], temp0, temp2, temp4)
							object[tempObjectPos].xvel = 0x40000
							object[tempObjectPos].yvel = 0x50000
							object[tempObjectPos].drawOrder = 4
							CreateTempObject(TypeName[Breakable Wall], temp1, temp3, temp4)
							object[tempObjectPos].xvel = 0x60000
							object[tempObjectPos].yvel = 0x60000
							object[tempObjectPos].drawOrder = 4
						end if
					end if
				else
					BoxCollisionTest(C_BOX, arrayPos0, -17, -32, 17, 32, object.entityPos, -22, -22, 22, 22)
					switch checkResult
					case 1
						object.gravity = GRAVITY_GROUND
						break
					case 2
						if object.speed > 0
							object.speed = 0
						end if
						break
					case 3
						if object.speed < 0
							object.speed = 0
						end if
						break
					end switch
				end if
			end if
			break
		case 44
			if object.xpos > object[arrayPos0].value6
				if object.xpos < object[arrayPos0].value7
					if object.entityPos == object[arrayPos0].value5
						object[arrayPos0].value2 = object.xpos
						object[arrayPos0].value2 -= object[arrayPos0].value6
						temp0 = object[arrayPos0].value2
						temp0 >>= 8
						temp1 = object[arrayPos0].value7
						temp1 -= object[arrayPos0].value6
						temp2 = temp1
						temp2 >>= 16
						temp0 /= temp2
						Sin(object[arrayPos0].value3, temp0)
						temp1 >>= 13
						object[arrayPos0].value3 *= temp1
						temp0 = object[arrayPos0].ypos
						temp0 -= 0x300000
						if object.ypos > temp0
							if object.yvel >= 0
								temp2 = object.collisionBottom
								FlipSign(temp2)
								temp2 <<= 16
								temp2 += object[arrayPos0].value4
								temp2 -= 0x80000
								object[arrayPos0].value0++
								object.ypos = object[arrayPos0].ypos
								object.ypos += temp2
								object.gravity = GRAVITY_GROUND
								object.yvel = 0
								object.floorSensorL = 1
								object.floorSensorC = 1
								object.floorSensorR = 1
							else
								object[arrayPos0].value5 = -2
							end if
						end if
					else
						if object.yvel >= 0
							temp0 = object.xpos
							temp0 -= object[arrayPos0].value6
							if temp0 > object[arrayPos0].value2
								temp0 = object[arrayPos0].value7
								temp0 -= object.xpos
								temp3 = object[arrayPos0].value7
								temp3 -= object[arrayPos0].value6
								temp3 -= object[arrayPos0].value2
								temp1 = temp0
								temp1 <<= 7
								temp1 /= temp3
							else
								temp1 = temp0
								temp1 <<= 7
								temp1 /= object[arrayPos0].value2
							end if
							Sin(temp2, temp1)
							temp2 *= object[arrayPos0].value4
							temp2 >>= 9
							temp2 -= 0x80000
							if object.yvel < 0x8000
								temp3 = temp2
								temp3 >>= 16
								temp4 = temp3
								temp3 -= 8
							else
								temp3 = temp2
								temp3 >>= 16
								temp4 = temp3
								temp4 += 8
							end if
							BoxCollisionTest(C_TOUCH, object[arrayPos0].entityPos, -0x400, temp3, 0x400, temp4, object.entityPos, -18, -22, 18, 22)
							if checkResult == 1
								object[arrayPos0].value0++
								object.ypos = object.collisionBottom
								FlipSign(object.ypos)
								object.ypos <<= 16
								object.ypos += object[arrayPos0].ypos
								object.ypos += temp2
								object.floorSensorL = 1
								object.floorSensorC = 1
								object.floorSensorR = 1
								object[arrayPos0].value5 = object.entityPos
								object.gravity = GRAVITY_GROUND
								object.yvel = 0
							end if
						end if
					end if
				else
					if object.entityPos == object[arrayPos0].value5
						object[arrayPos0].value5 = -2
						object[arrayPos0].value1 = 32
					end if
				end if
			else
				if object.entityPos == object[arrayPos0].value5
					object[arrayPos0].value5 = -2
					object[arrayPos0].value1 = 32
				end if
			end if
			break
		case 16
			temp7 = 0xA0000
			CallFunction(CheckeredBall_Function146)
			break
		case 15
			temp7 = 0x100000
			CallFunction(CheckeredBall_Function146)
			break
		case 47
			object[arrayPos0].ypos -= object[arrayPos0].value1
			BoxCollisionTest(C_PLATFORM, object[arrayPos0].entityPos, -32, -8, 32, 0, object.entityPos, -18, -22, 18, 22)
			if checkResult == 1
				object[arrayPos0].value0 = 1
				object.value13 = object[arrayPos0].value1
			end if
			object[arrayPos0].ypos += object[arrayPos0].value1
			break
		case 48
			object[arrayPos0].xpos -= object[arrayPos0].value3
			object[arrayPos0].ypos -= object[arrayPos0].value4
			BoxCollisionTest(C_PLATFORM, object[arrayPos0].entityPos, -32, -8, 32, 12, object.entityPos, -18, -22, 18, 22)
			if checkResult == 1
				object[arrayPos0].value0 = 1
				object.value12 = object[arrayPos0].value3
				object.value13 = object[arrayPos0].value4
			end if
			object[arrayPos0].xpos += object[arrayPos0].value3
			object[arrayPos0].ypos += object[arrayPos0].value4
			break
		case 49
			object[arrayPos0].ypos -= object[arrayPos0].value1
			BoxCollisionTest(C_PLATFORM, object[arrayPos0].entityPos, -32, -8, 32, 12, object.entityPos, -18, -22, 18, 22)
			if checkResult == 1
				object.value13 = object[arrayPos0].value1
			end if
			object[arrayPos0].ypos += object[arrayPos0].value1
			break
		case 50
			object[arrayPos0].ypos -= object[arrayPos0].value1
			BoxCollisionTest(C_PLATFORM, object[arrayPos0].entityPos, -32, -2, 32, 12, object.entityPos, -18, -22, 18, 22)
			if checkResult == 1
				object.value13 = object[arrayPos0].value1
			end if
			object[arrayPos0].ypos += object[arrayPos0].value1
			break
		case 46
			temp0 = object[arrayPos0].xpos
			temp1 = object[arrayPos0].ypos
			object[arrayPos0].xpos = object[arrayPos0].value1
			object[arrayPos0].ypos = object[arrayPos0].value2
			object[arrayPos0].xpos -= object[arrayPos0].value3
			object[arrayPos0].ypos -= object[arrayPos0].value4
			BoxCollisionTest(C_PLATFORM, object[arrayPos0].entityPos, -24, -8, 24, 8, object.entityPos, -18, -22, 18, 22)
			if checkResult == 1
				object.value12 = object[arrayPos0].value3
				object.value13 = object[arrayPos0].value4
			end if
			object[arrayPos0].xpos = temp0
			object[arrayPos0].ypos = temp1
			break
		case 52
			temp7 = 1
			CallFunction(CheckeredBall_Function147)
			break
		case 53
			temp7 = 0
			CallFunction(CheckeredBall_Function147)
			break
		case 40
			CheckEqual(object[arrayPos0].value6, 0)
			temp0 = checkResult
			CheckEqual(object.gravity, GRAVITY_GROUND)
			temp0 |= checkResult
			if temp0 == 1
				BoxCollisionTest(C_TOUCH, object[arrayPos0].entityPos, -12, object[arrayPos0].value0, 12, object[arrayPos0].value1, object.entityPos, -10, -22, 10, 22)
				if checkResult == 1
					if object.xvel > 0
						object.collisionPlane = object[arrayPos0].value3
						object.drawOrder = object[arrayPos0].value5
					else
						object.collisionPlane = object[arrayPos0].value2
						object.drawOrder = object[arrayPos0].value4
					end if
				end if
			end if
			break
		case 41
			CheckEqual(object[arrayPos0].value6, 0)
			temp0 = checkResult
			CheckEqual(object.gravity, GRAVITY_GROUND)
			temp0 |= checkResult
			if temp0 == 1
				BoxCollisionTest(C_TOUCH, object[arrayPos0].entityPos, object[arrayPos0].value0, -12, object[arrayPos0].value1, 12, object.entityPos, -22, -10, 22, 10)
				if checkResult == 1
					if object.yvel > 0
						object.collisionPlane = object[arrayPos0].value3
						object.drawOrder = object[arrayPos0].value5
					else
						object.collisionPlane = object[arrayPos0].value2
						object.drawOrder = object[arrayPos0].value4
					end if
				end if
			end if
			break
		case 66
			arrayPos1 = arrayPos0
			arrayPos1--
			if object[arrayPos1].value4 == 0
				switch object[arrayPos0].state
				case 4
				case 5
				case 6
					BoxCollisionTest(C_TOUCH, arrayPos0, -20, -16, 20, 16, object.entityPos, -22, -22, 22, 22)
					if checkResult == 1
						object[arrayPos0].value1--
						if object[arrayPos0].value1 == 0
							player.score += 1000
							object[arrayPos0].animationTimer = 0
							object[arrayPos0].animation = 4
							object[arrayPos1].state = 2
							object[arrayPos1].value6 = 0
							arrayPos1--
							ResetObjectEntity(arrayPos1, TypeName[Explosion], 0, object[arrayPos1].xpos, object[arrayPos1].ypos)
							arrayPos1--
							ResetObjectEntity(arrayPos1, TypeName[Explosion], 0, object[arrayPos1].xpos, object[arrayPos1].ypos)
							arrayPos1--
							ResetObjectEntity(arrayPos1, TypeName[Explosion], 0, object[arrayPos1].xpos, object[arrayPos1].ypos)
							arrayPos1--
							ResetObjectEntity(arrayPos1, TypeName[Explosion], 0, object[arrayPos1].xpos, object[arrayPos1].ypos)
							arrayPos1--
							ResetObjectEntity(arrayPos1, TypeName[Explosion], 0, object[arrayPos1].xpos, object[arrayPos1].ypos)
							object[arrayPos0].value0 = 0
							object[arrayPos0].state = 7
						else
							object[arrayPos0].animationTimer = 0
							object[arrayPos0].animation = 3
							object[arrayPos1].value4 = 32
							PlaySfx(SfxName[Boss Hit], 0)
						end if
					end if
					break
				end switch
			end if
			break
		case 69
			if object[arrayPos0].state == 1
				BoxCollisionTest(C_TOUCH, arrayPos0, -22, -22, 22, 22, object.entityPos, -22, -22, 22, 22)
				if checkResult == 1
					temp0 = object[arrayPos0].xpos
					temp0 -= object.value14
					temp1 = object[arrayPos0].ypos
					temp1 -= object.value15
					if object.xvel == 0
						object.xvel = temp0
						object.speed = object.xvel
					else
						if object.xvel < 0
							if temp0 > 0
								temp2 = temp0
								temp2 >>= 1
								temp0 += temp2
								object.xvel = temp0
								object.speed = object.xvel
							end if
						else
							if temp0 < 0
								temp2 = temp0
								temp2 >>= 1
								temp0 += temp2
								object.xvel = temp0
								object.speed = object.xvel
							end if
						end if
					end if
					if object.yvel == 0
						object.yvel = temp1
					else
						if object.yvel < 0
							if temp1 > 0
								temp2 = temp1
								temp2 >>= 1
								temp1 += temp2
								object.yvel = temp1
							end if
						else
							if temp1 < 0
								temp2 = temp1
								temp2 >>= 1
								temp1 += temp2
								object.yvel = temp1
							end if
						end if
					end if
				end if
			end if
			object.value14 = object[arrayPos0].xpos
			object.value15 = object[arrayPos0].ypos
			break
		case 74
			if arrayPos0 != object.entityPos
				temp0 = object.xpos
				temp0 -= object[arrayPos0].xpos
				Abs(temp0)
				temp0 >>= 17
				if temp0 >= 24
					temp0 = 23
				end if
				GetTableValue(temp6, temp0, CheckeredBall_table26)
				temp0 = temp6
				temp0 >>= 1
				temp6 += temp0
				temp6 -= 22
				temp7 = temp6
				FlipSign(temp7)
				temp0 = object.xvel
				temp1 = object.yvel
				temp2 = object.speed
				BoxCollisionTest(C_BOX, arrayPos0, -22, temp6, 22, temp7, object.entityPos, -22, -22, 22, 22)
				switch checkResult
				case 2
				case 3
					CheckGreater(temp0, 0)
					temp3 = checkResult
					CheckLower(object.xpos, object[arrayPos0].xpos)
					temp3 &= checkResult
					CheckLower(temp0, 0)
					temp4 = checkResult
					CheckGreater(object.xpos, object[arrayPos0].xpos)
					temp4 &= checkResult
					temp3 |= temp4
					if temp3 != 0
						object.xvel = object[arrayPos0].xvel
						object.speed = object[arrayPos0].speed
						object[arrayPos0].xvel = temp0
						object[arrayPos0].speed = temp2
					end if
					break
				case 1
					if object.xpos < object[arrayPos0].xpos
						object.speed -= 0xC00
						object.xvel -= 0xC00
						object[arrayPos0].speed += 0xC00
						object[arrayPos0].xvel += 0xC00
						object[arrayPos0].value5 += 0xC00
					else
						object.speed += 0xC00
						object.xvel += 0xC00
						object[arrayPos0].speed -= 0xC00
						object[arrayPos0].xvel -= 0xC00
						object[arrayPos0].value5 -= 0xC00
					end if
				case 4
					CheckGreater(temp1, 0)
					temp3 = checkResult
					CheckLower(object.ypos, object[arrayPos0].ypos)
					temp3 &= checkResult
					CheckLower(temp1, 0)
					temp4 = checkResult
					CheckGreater(object.ypos, object[arrayPos0].ypos)
					temp4 &= checkResult
					temp3 |= temp4
					if temp3 != 0
						object.yvel = object[arrayPos0].yvel
						object[arrayPos0].yvel = temp1
					end if
					break
				end switch
				BoxCollisionTest(C_TOUCH, arrayPos0, -22, temp6, 22, temp7, object.entityPos, -22, -22, 22, 22)
				if checkResult == 1
					if object.xpos < object[arrayPos0].xpos
						object.xpos -= 0x10000
					else
						object.xpos += 0x10000
					end if
					if object.ypos < object[arrayPos0].ypos
						object.ypos -= 0x10000
					else
						object.ypos += 0x10000
					end if
				end if
			end if
			break
		case 21
			switch object[arrayPos0].state
			case 0
				BoxCollisionTest(C_BOX, arrayPos0, -32, -24, 32, 32, object.entityPos, -18, -22, 18, 22)
				BoxCollisionTest(C_BOX, arrayPos0, -11, -48, 11, -24, object.entityPos, -18, -22, 18, 22)
				if checkResult == 1
					object[arrayPos0].state = 1
					stage.timeEnabled = 0
					if PlayerObject_SuperState == 1
						PlayerObject_SuperState = 2
					end if
					object[0].controlMode = -1
				end if
				break
			case 1
				BoxCollisionTest(C_BOX, arrayPos0, -32, -24, 32, 32, object.entityPos, -18, -22, 18, 22)
				BoxCollisionTest(C_BOX, arrayPos0, -11, -40, 11, -24, object.entityPos, -18, -22, 18, 22)
				break
			end switch
			break
		end switch
	next
	CallFunction(CheckeredBall_Function143)
	temp0 = object.value12
	temp0 |= object.value13
	if temp0 != 0
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_BOX, object.entityPos, -22, -22, 22, 22, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				object[currentPlayer].xpos += object.value12
				object[currentPlayer].ypos += object.value13
			end if
		next
		object.xpos += object.value12
		object.ypos += object.value13
		object.value12 = 0
		object.value13 = 0
	end if
	if object.outOfBounds == 1
		temp0 = object.xpos
		temp1 = object.ypos
		object.xpos = object.value7
		object.ypos = object.value8
		if object.outOfBounds == 1
			object.value1 = object.xpos
			object.value2 = object.ypos
			object.xvel = 0
			object.yvel = 0
			object.speed = 0
			object.value11 = 0
			object.value4 = 0
			object.value10 = 0
			object.value3 = 0
			object.value5 = 0
			object.value6 = 0
			if object.priority != PRIORITY_XBOUNDS_DESTROY
				object.priority = PRIORITY_ACTIVE_BOUNDS
			end if
			object.state = 0
		else
			object.xpos = temp0
			object.ypos = temp1
		end if
	end if
	object.value1 = object.xpos
	object.value1 &= -0x10000
	object.value2 = object.ypos
	object.value2 &= -0x10000
end event


event ObjectDraw
	object.rotation = object.value3
	object.rotation >>= 14
	temp0 = object.rotation
	temp0 += 8
	temp0 >>= 4
	temp0 &= 7
	temp0++
	DrawSprite(temp0)
	object.inkEffect = INK_ADD
	object.alpha = 160
	DrawSpriteFX(0, FX_INK, object.xpos, object.ypos)
end event


event ObjectStartup
	LoadSpriteSheet("GHZ/Objects2.gif")
	SpriteFrame(-24, -24, 48, 48, 1, 77)
	SpriteFrame(-24, -24, 48, 48, 50, 77)
	SpriteFrame(-24, -24, 48, 48, 148, 126)
	SpriteFrame(-24, -24, 48, 48, 99, 126)
	SpriteFrame(-24, -24, 48, 48, 50, 126)
	SpriteFrame(-24, -24, 48, 48, 1, 126)
	SpriteFrame(-24, -24, 48, 48, 197, 77)
	SpriteFrame(-24, -24, 48, 48, 148, 77)
	SpriteFrame(-24, -24, 48, 48, 99, 77)
	LoadAnimation("WreckingBall.ani")
	foreach (TypeName[Checkered Ball], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].gravity = GRAVITY_AIR
		object[arrayPos0].value7 = object.xpos
		object[arrayPos0].value8 = object.ypos
	next
	SetTableValue(TypeName[Checkered Ball], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(CheckeredBall_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(CheckeredBall_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
